package com.nq.service.impl;

import com.nq.dao.StFundApplyDetailMapper;
import com.nq.dao.UserPositionMapper;
import com.nq.dao.UserRechargeMapper;
import com.nq.dao.stock.StUserLevelMapper;
import com.nq.service.IStUserLevelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
public class StUserLevelServiceImpl implements IStUserLevelService {

    @Resource
    private StUserLevelMapper stUserLevelMapper;

    @Resource
    private UserRechargeMapper userRechargeMapper;

    @Resource
    private UserPositionMapper userPositionMapper;

    @Resource
    private StFundApplyDetailMapper stFundApplyDetailMapper;


    /**
     * 获取用户等级
     * @param userId
     * @return
     */
    @Override
    public Integer getUserLevelByUserId(Integer userId) {
        // 查询买入基金的价格
        Integer totalFundAmount = stFundApplyDetailMapper.queryUserBuyFundAmount(userId);

        // 获取用户等级
        Integer levelId = stUserLevelMapper.queryUserCurrentLevel(new BigDecimal(totalFundAmount));
        if (null == levelId) {
            levelId = 1;
        }

        return levelId;
    }

    @Override
    public BigDecimal getUserTransactionAmountByUserId(Integer userId) {
        // 查询买入基金的价格
        Integer totalFundAmount = stFundApplyDetailMapper.queryUserBuyFundAmount(userId);
        // 计算总交易金额
        BigDecimal totalAmount = new BigDecimal(totalFundAmount);

        return totalAmount;
    }
}
